home *** CD-ROM | disk | FTP | other *** search
- /*
- ** Subsystem: User Level mount for CD-ROM
- ** File Name: cdmount.c
- **
- ** This software is Copyright (c) 1991 by Kent Landfield.
- **
- ** Permission is hereby granted to copy, distribute or otherwise
- ** use any part of this package as long as you do not try to make
- ** money from it or pretend that you wrote it. This copyright
- ** notice must be maintained in any copy made.
- **
- ** Use of this software constitutes acceptance for use in an AS IS
- ** condition. There are NO warranties with regard to this software.
- ** In no event shall the author be liable for any damages whatsoever
- ** arising out of or in connection with the use or performance of this
- ** software. Any use of this software is at the user's own risk.
- **
- ** If you make modifications to this software that you feel
- ** increases it usefulness for the rest of the community, please
- ** email the changes, enhancements, bug fixes as well as any and
- ** all ideas to me. This software is going to be maintained and
- ** enhanced as deemed necessary by the community.
- **
- ** Kent Landfield
- ** sparky!kent
- ** kent@sparky.imd.sterling.com
- */
- #if !defined(lint) && !defined(SABER)
- static char SID[] = "@(#)cdmount.c 1.2 8/19/91";
- #endif
-
- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/stat.h>
-
- #define MNTPOINT "/cdrom"
-
- void usage(progname)
- char *progname;
- {
- (void) fprintf(stderr, "\nusage: %s [ -dhv ]\
- \n\noptions:\n\
- -d show the mount command without executing it\n\
- -h mount an ISO 9660 or High Sierra CD_ROM Filesystem\n\
- -v show the mount command and execute it\n\
- \n", progname);
- }
-
- int main(argc, argv)
- int argc;
- char **argv;
- {
- int getopt();
- char *strrchr();
-
- extern char *optarg;
- extern int optind;
- extern int opterr;
-
- char *cp;
- char cmd[256];
- int rc;
- int debug;
- int iso9660;
- struct stat stb;
-
- if ((cp = strrchr(argv[0],'/')) != NULL)
- ++cp;
- else
- cp = argv[0];
-
- /*
- ** Setup IFS for system() protection...
- */
- if (putenv("IFS= \t\n") != 0) {
- (void) fprintf(stderr,"%s: IFS putenv failed...\n", cp);
- return(1);
- }
-
- /*
- ** Setup PATH for execlp() protection...
- */
- if (putenv("PATH=/etc:/usr/etc:/bin:/usr/bin") != 0) {
- (void) fprintf(stderr,"%s: PATH putenv failed...\n", cp);
- return(1);
- }
-
- /*
- ** If the user is requesting to mount a CD..
- */
- if (strcmp(cp, "cdmount") == 0) {
- iso9660 = 0;
- opterr = 0;
- debug = 0;
- /*
- ** Assure that the mount point is there and in a
- ** directory and not a symbolic link ..
- */
- if (lstat(MNTPOINT, &stb) != 0) {
- (void) fprintf(stderr, "%s: mount point missing\n", MNTPOINT);
- return(1);
- }
- if ((stb.st_mode & S_IFMT) != S_IFDIR) {
- (void) fprintf(stderr, "%s: invalid mount point\n", MNTPOINT);
- return(1);
- }
-
- if (argc > 1) {
- while ((rc = getopt(argc, argv, "dhv")) != EOF) {
- switch (rc) {
- case 'd': /* debugging - does not run command. */
- debug = 1;
- break;
- case 'v': /* verbose - runs command. */
- debug = 2;
- break;
- case 'h':
- /*
- ** mount an ISO 9660 Standard or High
- ** Sierra Standard CD-ROM filesystem.
- */
- iso9660++;
- break;
- default:
- usage(cp);
- return(1);
- }
- }
- }
-
- /* build the command line.. */
-
- (void) sprintf(cmd, "/etc/mount -r %s -o nosuid /dev/sr0 %s",
- iso9660 ? "-t hsfs" : "", MNTPOINT);
- if (debug)
- (void) fprintf(stderr, "%s\n", cmd);
- if (debug != 1)
- rc = system(cmd);
- }
-
- /*
- ** The user is requesting to dismount a CD...
- */
- else if (strcmp(cp, "cdumount") == 0) {
- rc = system("/etc/umount /dev/sr0 && /usr/bin/eject /dev/sr0 2>/dev/null");
- }
-
- /*
- ** Improperly named/linked executables, I'm confused...
- */
- else {
- (void) fprintf(stderr, "%s: I don't know who I am... ? \n", cp);
- rc = 1;
- }
- return(rc >> 8);
- }
-